<template>
  <!-- 新增录入画面对话框-->
  <el-dialog
    :title="title"
    center
    :visible.sync="openState"
    width="1024px"
    :close-on-click-modal="false"
    :before-close="handleClose"
  >
    <el-form ref="editForm" :model="form" :rules="rules" label-width="110px">
      <!--交易础信息-->
      <el-card class="form-card txnInfo-card">
        <div slot="header" class="label-header-msg">
          <span>交易基础信息</span>
        </div>
        <el-row>
          <el-col :span="8">
            <el-form-item label="业务类型" prop="bizTypeCode">
              <el-select v-model="form.bizTypeCode" placeholder="业务类型" @change="bizTypeCodeChange">
                <el-option
                  v-for="dict in dictMap.BIZ_TYPE_125"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="业务种类" prop="bizCtgyCode">
              <el-select v-model="form.bizCtgyCode" placeholder="业务种类" @change="bizCtgyCodeChange">
                <el-option
                  v-for="dict in busTypeList"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="8">
              <el-form-item label="业务优先级" prop="bizPriority">
                <el-select v-model="form.bizPriority" placeholder="业务优先级">
                  <el-option
                    v-for="dict in dictMap.PRIORITY3CODE"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row> -->

          <!-- <el-row>
            <el-col :span="8">
              <el-form-item label="交易渠道" prop="transSource">
                <el-input
                  v-model="form.transSource"
                  :disabled="true"
                  placeholder="柜面交易"
                  style="width:195px"
                />
              </el-form-item>
            </el-col>-->
          <el-col :span="8">
            <el-form-item label="记账标志" prop="cbflag">
              <el-select v-model="form.cbflag" placeholder="记账标志">
                <el-option
                  v-for="dict in dictMap.CBFLAG"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="内部批序号" prop="batchNo">
              <acct-no-input v-model="form.batchNo" placeholder=""/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="交易币种" prop="curcd">
              <el-input v-model="form.curcd" placeholder="人民币-CNY" :disabled="true" style="width: 195px" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="交易金额" prop="amount">
              <ht-amount-input
                v-model="form.amount"
                placeholder="交易金额"
                style="width: 195px"
                @keyup.enter.native="checkAmountLimit()"
              ></ht-amount-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="大写金额" prop="bAmount">
              <ht-amount-upper :inputValue="form.amount" placeholder="交易金额" style="width: 195px"></ht-amount-upper>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="附言" prop="content">
              <el-input type="textarea" v-model="form.content" placeholder="附言" maxlength="140" show-word-limit/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>

      <!--付款人信息-->
      <el-card class="form-card payerInfo-card">
        <div slot="header" class="label-header-msg">
          <span>付款人信息</span>
        </div>
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="付款人账号" prop="payerActno">
              <acct-no-input
                v-model="form.payerActno"
                placeholder="付款人账号"
                @keyup.enter.native="getActNoInfo('payerActNo')"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-row>
              <el-button type="primary" icon="el-icon-search" plain @click="openPayerDialog('payerActno')">
                账号查找
              </el-button>
            </el-row>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="付款人名称" prop="payerName">
            <el-input v-model="form.payerName" placeholder="付款人名称" />
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="付款人地址" prop="payerAddr">
            <el-input v-model="form.payerAddr" placeholder="付款人地址" />
          </el-form-item>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="8">
            <div class="grid-payer">
              <el-form-item label="付款行行号" prop="payerBrno">
                <el-input
                  v-model="form.payerBrno"
                  placeholder="付款行行号"
                  :disabled="true"
                />
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="3">
            <el-form-item></el-form-item>
          </el-col>
          <el-col :span="13">
            <el-form-item label="付款行行名" prop="payerBrName" label-width="130px">
              <el-input v-model="form.payerBrName" placeholder="付款行行名" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="8">
            <div class="grid-payer">
              <el-form-item label="付款人开户行号" prop="payerAccBrno">
                <acct-no-input
                  v-model="form.payerAccBrno"
                  placeholder="付款人开户行行号"
                  @keyup.enter.native="getBankInf('payerAccBrno', form.payerAccBrno)"
                />
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="3">
            <div class="grid-payer">
              <el-button type="primary" icon="el-icon-search" plain @click="openBankBranchDialog('payerAccBrno')">
                行号查找
              </el-button>
            </div>
          </el-col>
          <el-col :span="13">
            <el-form-item label="付款人开户行行名" prop="payerAccBrName" label-width="130px">
              <el-input v-model="form.payerAccBrName" placeholder="付款人开户行行名" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>

      <!--收款人信息-->
      <el-card class="form-card payeeInfo-card">
        <div slot="header" class="label-header-msg">
          <span>收款人信息</span>
        </div>
        <el-row :gutter="10">
          <el-col :span="12">
            <div class="grid-payee">
              <el-form-item label="收款人账号" prop="payeeActno">
                <acct-no-input
                  v-model="form.payeeActno"
                  placeholder="收款人账号"
                  @keyup.enter.native="getActNoInfo('payeeActNo')"
                />
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="grid-payee">
              <el-button type="primary" icon="el-icon-search" plain @click="openPayeeDialog('payeeActno')">
                账号查找
              </el-button>
            </div>
          </el-col>
        </el-row>
        <el-form-item label="收款人名称" prop="payeeName">
          <el-input v-model="form.payeeName" placeholder="收款人名称" />
        </el-form-item>
        <el-form-item label="收款人地址" prop="payeeAddr">
          <el-input v-model="form.payeeAddr" placeholder="收款人地址" />
        </el-form-item>
        <el-row :gutter="10">
          <el-col :span="8">
            <div class="grid-payee">
              <el-form-item label="收款行行号" prop="payeeBrno">
                <acct-no-input
                  v-model="form.payeeBrno"
                  placeholder="收款行行号"
                  :readonly="form.bizTypeCode === 'A202'"
                  @keyup.enter.native="getBankInf('payeeBrno', form.payeeBrno)"
                />
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="3">
            <div class="grid-payee">
              <el-button
                type="primary"
                icon="el-icon-search"
                plain
                :disabled="form.bizTypeCode === 'A202'"
                @click="openBankBranchDialog('payeeBrno')"
              >
                行号查找
              </el-button>
            </div>
          </el-col>
          <el-col :span="13">
            <el-form-item label="收款行行名" prop="payeeBrName" label-width="130px">
              <el-input v-model="form.payeeBrName" placeholder="收款行行名" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="8">
            <div class="grid-payee">
              <el-form-item label="收款人开户行号" prop="payeeAccBrno">
                <acct-no-input
                  v-model="form.payeeAccBrno"
                  placeholder="收款人开户行行号"
                  @keyup.enter.native="getBankInf('payeeAccBrno', form.payeeAccBrno)"
                />
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="3">
            <div class="grid-payee">
              <el-button type="primary" icon="el-icon-search" plain @click="openBankBranchDialog('payeeAccBrno')">
                行号查找
              </el-button>
            </div>
          </el-col>
          <el-col :span="13">
            <el-form-item label="收款人开户行行名" prop="payeeAccBrName" label-width="130px">
              <el-input v-model="form.payeeAccBrName" placeholder="收款人开户行行名" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm(null)">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
      <el-button v-show="ifShowDelBtn" type="danger" @click="delTran">删 除</el-button>
    </div>
    <bank-branch-dialog ref="bankBranchDialog" @confirm="confirmBankBranch"></bank-branch-dialog>
    <payee-dialog ref="payeeDialog" @confirm="confirmPayee"></payee-dialog>
    <payer-dialog ref="payerDialog" @confirm="confirmPayer"></payer-dialog>
  </el-dialog>
</template>
<script>
import { addTxn, hvpsBepsCreditModifyDetail, save125, upd125, updTxn } from "@/api/cnaps/baseBiz/send/beps/beps.js";
import { detail, delTxn } from "@/api/cnaps/baseBiz/send/sendCommon.js";
import { getBankInfByBankCode } from "@/api/cnaps/common/bankInfo";
import { isLessThenHvpsMinLimitNew } from "@/api/cnaps/common/cp2SysParam";
import BankBranchDialog from "@/views/components/BankBranchDialog";
import PayeeDialog from "@/views/components/PayeeDialog";
import PayerDialog from "@/views/components/PayerDialog";
import HtAmountInput from "@/views/components/HtAmountInput";
import HtAmountUpper from "@/views/components/HtAmountUpper";
import { mapGetters } from "vuex";
import AcctNoInput from "@/views/components/AcctNoInput/index.vue";


import { config } from "process";
import { deflate } from "zlib";

export default {
  name: "EditInfo",
  components: {
    PayeeDialog,
    PayerDialog,
    BankBranchDialog,
    HtAmountInput,
    HtAmountUpper,
    AcctNoInput,
  },
  props: {
    dictMap: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  computed: {
    ...mapGetters(["globalBusData"]),
  },
  data() {
    return {
      busTypeList: [],
      id: "",
      title: "",
      pkgNo: "",
      // 是否显示弹出层
      openState: false,
      ifShowDelBtn: false,

      // 字段可编辑控制

      // 表单参数
      form: {
        amount: "0.00",
      },
      // 表单校验
      rules: {
        bizTypeCode: [{ required: true, message: "请输入业务类型", trigger: "blur" }],
        bizCtgyCode: [{ required: true, message: "请输入业务种类", trigger: "blur" }],
        bizPriority: [{ required: true, message: "请输入业务优先级", trigger: "blur" }],
        payerBrno: [{ required: true, max: 14, message: "请输入付款行号", trigger: "blur" }],
        payerBrName: [{ required: true, max: 60, message: "请输入付款行名", trigger: "blur" }],
        payerAccBrno: [{ required: true, message: "请输入付款开户行号", trigger: ['blur', 'change'] },
                       {max: 35, message: "最大长度为35位", trigger: "blur"}],
        payerAccBrName: [{ max: 140, trigger: "blur" }],
        payerActno: [{ required: true, message: "请输入付款人账号", trigger: ['blur', 'change'] },
                     {max: 32, message: "最大长度为32位", trigger: "blur"}],
        payerName: [{ required: true, message: "请输入付款人名称", trigger: ['blur', 'change'] },
                    {max: 60, message: "最大长度为60位", trigger: "blur"}],
        payerAddr: [{ max: 70,message: "最大长度为70位", trigger: "blur" }],
        payeeActno: [{ required: true, message: "请输入收款人账号", trigger: ['blur', 'change'] },
                     {max: 32, message: "最大长度为32位", trigger: "blur"}],
        payeeName: [{ required: true, message: "请输入收款人名称", trigger: ['blur', 'change'] },
                    {max: 60, message: "最大长度为60位", trigger: "blur"}],
        payeeAddr: [{ max: 70,message: "最大长度为70位", trigger: "blur" }],
        payeeBrno: [{ required: true, message: "请输入收款行号", trigger: ['blur', 'change'] },
                    {max: 14, message: "最大长度为14位", trigger: "blur"}],
        payeeBrName: [{ required: true, message: "请输入收款行名", trigger: "blur" },
                      {max: 60, message: "最大长度为60位", trigger: "blur"}],
        payeeAccBrno: [{ required: true, message: "请输入收款开户行号", trigger: ['blur', 'change'] },
                       {max: 35, message: "最大长度为35位", trigger: "blur"}],
        payeeAccBrName: [{ max: 140,message: "最大长度为140位", trigger: "blur" }],
        agency1: [{ max: 35, trigger: "blur" }],
        agency1name: [{ max: 140, trigger: "blur" }],
        agency2: [{ max: 35, trigger: "blur" }],
        agency2name: [{ max: 140, trigger: "blur" }],
        amount: [{ required: true,message: "请输入交易金额", trigger: "blur" }],
        remarksAll: [{ required: false, max: 140, trigger: "blur" }],
        batchNo : [{ required: true, message: "请输入内部批序号", trigger: "blur" },
                  {max: 20, message: "最大长度20位", trigger: "blur"}],
      },
    };
  },
  mounted() {},
  methods: {
    // 表单重置
    reset() {
      this.resetForm("editForm");
      this.$set(this, "form", {});
    },
    // 关闭回掉
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          this.reset();
          done();
        })
        .catch((_) => {});
    },

    bizTypeCodeChange(code) {
      //联动修改bizCtgyCode
      let dictKeyPre = `BIZ_CTGY_BEPS_${code}`;
      this.getDicts(dictKeyPre).then((response) => {
        this.busTypeList = response.result;
        this.$set(this.form, "bizCtgyCode", this.busTypeList[0].value);
      });

      //画面输入要素修改------------------
      if (code == "A202") {
        //城市商业银行汇票
        this.$set(this.form, "payeeBrno", "904290099992");
        this.$set(this.form, "payeeBrName", "城银清算服务有限责任公司");
        this.$set(this.form, "payeeAccBrno", "904290099992");
        this.$set(this.form, "payeeAccBrName", "城银清算服务有限责任公司");
        this.$set(this.rules.payeeActno[0], "required", false);
        this.$set(this.rules.payeeName[0], "required", false);
        this.$set(this.rules.payeeAccBrno[0], "required", false);
      }
      if (code !== "A202") {
        this.$set(this.rules.payeeActno[0], "required", true);
        this.$set(this.rules.payeeName[0], "required", true);
        this.$set(this.rules.payeeAccBrno[0], "required", true);
      }
      if (code !== "A102") {
        this.$set(this.rules.remarksAll[0], "required", false);
      }
      if (code == "A102") {
        this.$set(this.rules.remarksAll[0], "required", true);
      }
    },
    bizCtgyCodeChange() {
      //业务种类变化，城商行商业汇票特殊处理
      //城市商业银行汇票资金移存”时，“付款人开户行行号、付款人账号、付款人名称”必填，
      //“收款人开户行行号、收款人账号、收款人名称”可选填
      //城市商业银行汇票资金清算、城市商业银行汇票资金多余划回、城市商业银行汇票资金未用退回”时，
      //“收款人开户行行号、收款人账号、收款人名称”必填，
      //“付款人开户行行号、付款人账号、付款人名称”可选填；
      if (this.form.bizTypeCode == "A202") {
        switch (this.form.bizCtgyCode) {
          case "02901": {
            this.$set(this.rules.payeeActno[0], "required", false);
            this.$set(this.rules.payeeName[0], "required", false);
            this.$set(this.rules.payeeAccBrno[0], "required", false);
            this.$set(this.rules.payerActno[0], "required", true);
            this.$set(this.rules.payerName[0], "required", true);
            this.$set(this.rules.payerAccBrno[0], "required", true);
            break;
          }
          case "02902":
          case "02903":
          case "02904": {
            this.$set(this.rules.payerActno[0], "required", false);
            this.$set(this.rules.payerName[0], "required", false);
            this.$set(this.rules.payerAccBrno[0], "required", false);
            this.$set(this.rules.payeeActno[0], "required", true);
            this.$set(this.rules.payeeName[0], "required", true);
            this.$set(this.rules.payeeAccBrno[0], "required", true);
            break;
          }
          default: {
            this.$set(this.rules.payerActno[0], "required", true);
            this.$set(this.rules.payerName[0], "required", true);
            this.$set(this.rules.payerAccBrno[0], "required", true);
            this.$set(this.rules.payeeActno[0], "required", true);
            this.$set(this.rules.payeeName[0], "required", true);
            this.$set(this.rules.payeeAccBrno[0], "required", true);
            break;
          }
        }
      }
    },
    // 回车查证账号信息
    getActNoInfo(actNoType) {
      if (actNoType === "payeeActNo") {
        var actNo = this.form.payeeActno;
        getOtherCustByActno(actNo).then((response) => {
          if (response.code == "S" && response.result !== null) {
            this.$set(this.form, "payeeActno", response.result.actNo);
            this.$set(this.form, "payeeName", response.result.name);
            this.$set(this.form, "payeeBrno", response.result.rcvBrno);
            this.$set(this.form, "payeeBrName", response.result.rcvBrname);
            this.$set(this.form, "payeeAddr", response.result.addr);
            this.$set(this.form, "payeeAccBrno", response.result.accBrno);
            this.$set(this.form, "payeeAccBrName", response.result.accBrnoName);
          } else {
            this.msgSuccess("无历史付款记录");
            this.$set(this.form, "payeeName", null);
            this.$set(this.form, "payeeBrno", null);
            this.$set(this.form, "payeeBrName", null);
            this.$set(this.form, "payeeAddr", null);
            this.$set(this.form, "payeeAccBrno", null);
            this.$set(this.form, "payeeAccBrName", null);
          }
        });
      } else {
        var actNo = this.form.payerActno;
        getCustByActno(actNo).then((response) => {
          if (response.code == "S" && response.result !== null) {
            this.$set(this.form, "payerActno", response.result.actNo);
            this.$set(this.form, "payerName", response.result.name);
            this.$set(this.form, "payerAddr", response.result.addr);
          } else {
            this.msgSuccess("查无此账号");
            this.$set(this.form, "payerName", null);
            this.$set(this.form, "payerAddr", null);
          }
        });
      }
    },
    // 检查大额交易金额上限
    checkAmountLimit() {
      isLessThenHvpsMinLimitNew(this.form.bizTypeCode, this.form.bizCtgyCode, this.form.bizPriority, this.form.amount);
    },

    openBankBranchDialog(fromFlag = "") {
      this.$refs.bankBranchDialog.show(fromFlag);
    },
    confirmBankBranch(fromFlag, row) {
      if (fromFlag == "payeeBrno") {
        this.$set(this.form, "payeeBrno", row.bankCode);
        this.$set(this.form, "payeeBrName", row.orgFullname);
      } else if (fromFlag == "payerAccBrno") {
        this.$set(this.form, "payerAccBrno", row.bankCode);
        this.$set(this.form, "payerAccBrName", row.orgFullname);
      } else if (fromFlag == "payerBrno") {
        this.$set(this.form, "payerBrno", row.bankCode);
        this.$set(this.form, "payerBrName", row.orgFullname);
      } else if (fromFlag == "payeeAccBrno") {
        this.$set(this.form, "payeeAccBrno", row.bankCode);
        this.$set(this.form, "payeeAccBrName", row.orgFullname);
      } else if (fromFlag == "agency1") {
        this.$set(this.form, "agency1", row.bankCode);
        this.$set(this.form, "agency1name", row.orgFullname);
      } else if (fromFlag == "agency2") {
        this.$set(this.form, "agency2", row.bankCode);
        this.$set(this.form, "agency2name", row.orgFullname);
      }
    },
    //回车取行号信息
    getBankInf(searchType, bankCode) {
      getBankInfByBankCode(bankCode).then((response) => {
        if (response.code == "S" && response.result !== null) {
          switch (searchType) {
            case "payerBrno":
              this.$set(this.form, "payerBrno", response.result.bankCode);
              this.$set(this.form, "payerBrName", response.result.orgFullname);
              break;
            case "payerAccBrno":
              this.$set(this.form, "payerAccBrno", response.result.bankCode);
              this.$set(this.form, "payerAccBrName", response.result.orgFullname);
              break;
            case "payeeBrno":
              this.$set(this.form, "payeeBrno", response.result.bankCode);
              this.$set(this.form, "payeeBrName", response.result.orgFullname);
              break;
            case "payeeAccBrno":
              this.$set(this.form, "payeeAccBrno", response.result.bankCode);
              this.$set(this.form, "payeeAccBrName", response.result.orgFullname);
              break;
            case "agency1":
              this.$set(this.form, "agency1", response.result.bankCode);
              this.$set(this.form, "agency1name", response.result.orgFullname);
              break;
            case "agency2":
              this.$set(this.form, "agency2", response.result.bankCode);
              this.$set(this.form, "agency2name", response.result.orgFullname);
              break;
          }
        } else {
          this.msgSuccess("查无此行号");
          switch (searchType) {
            case "payerBrno":
              this.$set(this.form, "payerBrName", null);
              break;
            case "payerAccBrno":
              this.$set(this.form, "payerAccBrName", null);
              break;
            case "payeeBrno":
              this.$set(this.form, "payeeBrName", null);
              break;
            case "payeeAccBrno":
              this.$set(this.form, "payeeAccBrName", null);
              break;
            case "agency1":
              this.$set(this.form, "agency1name", null);
              break;
            case "agency2":
              this.$set(this.form, "agency2name", null);
              break;
          }
        }
      });
    },
    openPayeeDialog(fromFlag = "") {
      this.$refs.payeeDialog.show(fromFlag);
    },
    confirmPayee(fromFlag, row) {
      if (fromFlag == "payeeActno") {
        this.$set(this.form, "payeeActno", row.actNo);
        this.$set(this.form, "payeeName", row.name);
        this.$set(this.form, "payeeBrno", row.rcvBrno);
        this.$set(this.form, "payeeBrName", row.rcvBrname);
        this.$set(this.form, "payeeAddr", row.addr);
        this.$set(this.form, "payeeAccBrno", row.accBrno);
        this.$set(this.form, "payeeAccBrName", row.accBrnoName);
      }
    },
    openPayerDialog(fromFlag = "") {
      this.$refs.payerDialog.show(fromFlag);
    },
    confirmPayer(fromFlag, row) {
      if (fromFlag == "payerActno") {
        this.$set(this.form, "payerActno", row.actNo);
        this.$set(this.form, "payerName", row.name);
        this.$set(this.form, "payerAddr", row.addr);
      }
    },
    show(id = "", pkgNo = "") {
      this.reset();
      this.pkgNo = pkgNo;
      this.id = id;
      this.title = "小额定期贷记业务录入";
      this.openState = true;
      this.ifShowDelBtn = false;

      // 初始化选择
      this.$set(this.form, "bizTypeCode", this.dictMap.BIZ_TYPE_125[0].value);
      this.bizTypeCodeChange(this.form.bizTypeCode);
      this.$set(this.form, "bizPriority", this.dictMap.PRIORITY3CODE[0].value);
      this.$set(this.form, "custflag1", this.dictMap.CUST_FLAG1[0].value);
      this.$set(this.form, "cbflag", this.dictMap.CBFLAG[0].value);
      this.$set(this.form, "payerBrno", this.globalBusData.cnapsBrno);
      this.$set(this.form, "payerBrName", this.globalBusData.cnapsBrname);
      this.$set(this.form, "payerAccBrno", this.globalBusData.cnapsBrno);
      this.$set(this.form, "payerAccBrName", this.globalBusData.cnapsBrname);
      this.$set(this.form, "curcd", 'CNY');

      if (id) {
        this.title = "小额定期贷记业务修改";
        this.ifShowDelBtn = true;

        // 如果传了ID 这里查询一个已经存在的数据
        hvpsBepsCreditModifyDetail({
          id: this.id,
          pkgId: this.pkgNo,
        }).then((res) => {
          this.$set(this, "form", res.result);
        });
      }
    },

    cancel() {
      this.openState = false;
      this.reset();
      this.$emit("editComplete", false);
    },
    submitCheck(res) {
      if (res.code === "C") {
        this.$confirm(res.message, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.submitForm(res.result);
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消执行'
          });
          return;
        });
      }
    },
    /** TODO提交按钮 */
    submitForm: function (pass) {
      this.$refs["editForm"].validate((valid) => {
        if (valid) {
          this.form.pass = pass;
          //如果有ID 则是修改
          if (this.id) {
            upd125(this.form).then((res) => {
              this.submitCheck(res);
              if (res.code === "S") {
                this.msgSuccess("修改成功");
                this.$emit("editComplete", true);
                this.openState = false;
              }
            });
          } else {
            save125(this.form).then((res) => {
              this.submitCheck(res);
              if (res.code === "S") {
                this.msgSuccess("新增成功");
                this.$alert(`CORE_ID: ${res.result.rspId}`, "生成交易流水号", {
                  confirmButtonText: "确定",
                  //刷新一下查询列表 TODO
                  callback: (action) => {
                  },
                });
                this.$emit("editComplete", true);
                this.openState = false;
              }
            });
          }
        }
      });
    },
    /** 删除 按钮 */
    delTran: function () {
      if (this.id) {
        this.$confirm("确认删除吗？", "交易删除提示", { type: "warning" }).then((_) => {
          delTxn({ id: this.id }).then((res) => {
            this.msgSuccess("删除成功");

            this.$emit("editComplete", true);
            this.openState = false;
          });
        });
      }
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
